﻿using Application.Dto;
using Application.IAppSrevices;
using AutoMapper;
using Domain.Entitys;
using Domain.Repositorys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.AppSrevices
{
    public class UserService : IUserService
    {
        private readonly IMapper mapper;
        private readonly IUserRepositoy userRepositoy;

        public UserService(IUserRepositoy userRepositoy,IMapper mapper)
        {
            this.userRepositoy = userRepositoy;
            this.mapper = mapper;
        }

        /// <summary>
        /// 根据角色编号查询对应的角色职位
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public UR GetUR(int id)
        {
            return userRepositoy.GetUR(id);
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<User> Login(UserLogin userLogin)
        {
            User user = mapper.Map<User>(userLogin);
            return await userRepositoy.Login(user);
        }

        /// <summary>
        /// 删除角色数据
        /// </summary>
        /// <param name="roleDeleteDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int RolesDelete(RoleDeleteDto roleDeleteDto)
        {
            Roles roles = mapper.Map<Roles>(roleDeleteDto);
            return userRepositoy.RolesDelete(roles);
        }

        public int URCount()
        {
            return userRepositoy.URCount();
        }

        public List<UR> URFill()
        {
            return userRepositoy.URFill();
        }

        /// <summary>
        /// 查询全部用户角色
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<UR> URFill1(int a, int b)
        {
            return userRepositoy.URFill1(a,b);
        }

        /// <summary>
        /// 查询最后一条用户数据
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public User UserDesc()
        {
            return userRepositoy.UserDesc();
        }

        /// <summary>
        /// 添加用户角色表
        /// </summary>
        /// <param name="userRolesAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int UserRolesAdd(UserRolesAddDto userRolesAddDto)
        {
            UserRoles userRoles = mapper.Map<UserRoles>(userRolesAddDto);
            return userRepositoy.UserRolesAdd(userRoles);
        }

        /// <summary>
        /// 根据用户ID查询角色ID
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public UserRoles UserRroesById(int uid)
        {
            return userRepositoy.UserRroesById(uid);
        }

        /// <summary>
        /// 修改用户角色表
        /// </summary>
        /// <param name="userRoles"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int UserRroesUpdate(UserRoles userRoles)
        {
            return userRepositoy.UserRroesUpdate(userRoles);
        }

        public List<User> UsersFill()
        {
            return userRepositoy.UsersFill();
        }
    }
}
